﻿using BusinessLayer.VDataEntities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessLayer.DatabaseEntities;
using BusinessLayer;

namespace BusinessLayer
{
   public class AdminBusiness
    {
       public static VSuperDataEntity Login(VLoginEntity login) {

           return null;
       }

       /// <summary>
       /// 通过用户名获得用户信息
       /// </summary>
       /// <param name="userName"></param>
       /// <returns></returns>
       public static VEndUser GetEndUserInfo(string userName) { 
          using(CustomerServiceCenterEntities entities = new CustomerServiceCenterEntities ()){
              var endUserInfo = from info in entities.EndUser
                                where info.UserName.Equals(userName.Trim()) && info.IsActive == true
                                select new VEndUser
                                {
                                    ClientID = info.ClientID,
                                    ID = info.ID,
                                    Name = info.UserName,
                                };
              return endUserInfo.FirstOrDefault();
          }
       }


       public static void ResetPassword(long OperatorID,string PassWord,string OldPassword = null) {
           using (CustomerServiceCenterEntities entities = new CustomerServiceCenterEntities()) {
               var operatorInfo = (from info in entities.Operator
                                   where (info.ID == OperatorID) && (info.IsActive == true) && (OldPassword == null ?(true):info.Password.Equals(OldPassword))
                                   select info).FirstOrDefault();
               if (null != operatorInfo)
               {
                   operatorInfo.Password = PassWord;
               }
               entities.SaveChanges();
           }
       }

       public static Operator FindOperator(long OperatorID,string Password) {
           using (CustomerServiceCenterEntities entities = new CustomerServiceCenterEntities())
           {
               var operatorInfo = (from info in entities.Operator
                                   where (info.ID == OperatorID) && (info.IsActive == true) && (info.Password.Equals(Password))
                                   select info).FirstOrDefault();
               return operatorInfo;
           }
       }



    }
}
